package com.erp.erp_mask.controller;

import com.erp.erp_mask.pojo.TPurchase;
import com.erp.erp_mask.service.TPurchaseService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/pur")
public class TPurchasetongjiController {

    @Resource
    private TPurchaseService tPurchaseService;

    @GetMapping("/order")
    public ModelAndView modelAndView() {
        return new ModelAndView("/pur/purchasetong");
    }

    @GetMapping("/tongji")
    public List<Object> tongji() {
        List<Object> objects = new ArrayList<>();
        List<TPurchase> list = tPurchaseService.tongjiChase();
        for (TPurchase cc : list) {
            int num = cc.getChaseNumber();
            String ming = cc.getChaseName();
            objects.add(new Object() {
                public int value = num;
                public String name = ming;
                @Override
                public String toString() {
                    return "{" + num + "," + ming + "}";
                }
            });
        }
        return objects;
    }
}
